<template>
    <transition name="fade">
        <div :class="['s-message',type]" v-if="isShow">
            <s-icon :type="icon" />
            <span class="text">{{ props.text }}</span>
        </div>
    </transition >
</template>

<script lang="ts" setup>
import { MESSAGE_TIMEOUT } from "@/utils"
import { SIcon } from "@/components"
import { ref, onMounted, computed } from "vue"
import { IconTypes } from "types"
const props = defineProps({
   text: {
      type: String,
      default: ""
   },
   type: {
      type: String,
      default: "warn" // warn 警告  error 错误  success 成功
   },
   timeout: {
      type: Number,
      default: MESSAGE_TIMEOUT
   }
})

const icon = computed(() => {
   return `icon-${props.type}-fill` as IconTypes
})

const isShow = ref<boolean>(false)
onMounted(() => {
   isShow.value = true
   setTimeout(() => {
      isShow.value = false
   }, props.timeout)
})
</script>

<style scoped lang="less">
.fade-enter-active{
  animation: fade .5s;
}
.fade-leave-active {
  animation: fade .5s reverse;
}

// /* 定义帧动画 */
@keyframes fade {
  0% {
    opacity: 0;
    transform: translateY(-50px);
  }

  100% {
    opacity: 1;
  }
}

.s-message {
    min-width: 300px;
    max-width: 350px;
    padding: 8px;
    position: fixed;
    z-index: 9999;
    left: 50%;
    margin-left: -150px;
    top: 25px;
    border-radius: 4px;
    .text {
        vertical-align: middle;
        margin-left: 8px;
    }
    &.warn{
      color: @warn;
      background: #fff7e6;
      border-color: #ffe7ba;
   };
   &.error{
      color: @danger;
      background: #fff1f0;
      border-color: #ffccc7;
   }
   &.success {
      color: @success;
      background: #f6ffed;
      border-color: #d9f7be;
   }
   &.info {
      color: @primary;
      background: #e6f7ff;
      border-color: #bae7ff;
   }
}
</style>
